home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACAPP
/
PRE_3
/
UPROGRES
/
UPROGRES.P
< prev
Wrap
Text File
|
1990-08-20
|
4KB
|
151 lines
{
A simple progress bar indicator for MacApp. Implemented as a view for
simplicity's sake. Hey, it works for me, but comments are welcome.
⌐ 1990 Brian P. Arnold
All Rights Reserved.
Heck, go ahead and even use it if you want in commercial applications,
and even bundle it in other MacApp source code whereby you'd be making
a profit and I wouldn't. I don't care.
HOW TO USE:
Create the view using whatever method you prefer: I prefer ViewEdit.
Call IProgressView after getting a reference to the view.
Call IncrementProgress repeatedly to automatically increment progress
("smooth progress"), or call DoProgress to alter the current value.
Note that the view relies on your processing update events to draw
accurately, and it expects silly things like calling IncrementProgress
exactly the number of times in fMaxValue except if you use DoProgress.
I don't think it likes decrementing but nobody likes backward "progress"...
If your progress indicator is spring-loaded and isn't used often
or for long periods, resegment the code appropriately.
TO DO:
Subclass a timer progress view that uses Ticks and automatic updating.
Implement as a TControl.
}
UNIT UProgressView;
INTERFACE
USES
UMacApp;
TYPE
TProgressView = OBJECT( TView )
fCurValue,
fMaxValue: INTEGER;
PROCEDURE TProgressView.IProgressView( maxValue: INTEGER );
{ initialize the values }
PROCEDURE TProgressView.Draw( area: Rect );
OVERRIDE;
{ draw the progress indicator }
PROCEDURE TProgressView.IncrementProgress;
{ increment curvalue, invalidate that part of the view }
PROCEDURE TProgressView.DoProgress( newCurVal: INTEGER );
{ update curvalue, invalidate the difference }
END;
PROCEDURE InitUProgressView;
{ avoid dead-stripping }
IMPLEMENTATION
{------------------------------------------------------------------------------------------}
{$S AInit}
PROCEDURE InitUProgressView;
BEGIN
IF gDeadStripSuppression THEN
IF Member( TObject( NIL ), TProgressView ) THEN ;
END;
{------------------------------------------------------------------------------------------}
{$S AInit}
PROCEDURE TProgressView.IProgressView( maxValue: INTEGER );
{ initialize the values }
BEGIN
fCurValue := 0;
fMaxValue := maxValue;
END;
{------------------------------------------------------------------------------------------}
{$S ARes}
PROCEDURE TProgressView.Draw( area: Rect );
OVERRIDE;
{ draw the progress indicator }
VAR
drawRect: Rect;
BEGIN
SELF.GetQDExtent( drawRect );
(* draw the border *)
PenPat( black );
FrameRect( drawRect );
(* figure out the "progress" *)
InsetRect( drawRect, 1, 1 );
SetRect( drawRect, drawRect.left,
drawRect.top,
( drawRect.right * fCurValue ) DIV fMaxValue,
drawRect.bottom );
(* draw the "progress" *)
PenPat( dkGray );
PaintRect( drawRect );
END;
{------------------------------------------------------------------------------------------}
{$S ARes}
PROCEDURE TProgressView.IncrementProgress;
{ increment curvalue, invalidate that part of the view }
BEGIN
DoProgress( fCurValue + 1 );
END;
{------------------------------------------------------------------------------------------}
{$S ARes}
PROCEDURE TProgressView.DoProgress( newCurVal: INTEGER );
{ update curvalue, invalidate the difference }
VAR
deltaProgress: Rect;
BEGIN
IF Focus THEN ;
GetQDExtent( deltaProgress );
InsetRect( deltaProgress, 1, 1 );
(* set left edge to current value position *)
deltaProgress.left := ( deltaProgress.right * fCurValue ) DIV fMaxValue;
fCurValue := newCurVal;
IF fCurValue > fMaxValue THEN BEGIN
IF qDebug THEN
Writeln('TProgressView.DoProgress: tried to set fCurValue > fMaxValue' );
fCurValue := fMaxValue;
END;
(* set right edge to new value position (+1 is assumption on horizontal pensize) *)
deltaProgress.right := ( ( deltaProgress.right * fCurValue ) DIV fMaxValue) + 1;
(* invalidate the difference *)
InvalidRect( deltaProgress );
END;
END.